'use strict';

const moment = require('moment');

module.exports = app => {
  const { Sequelize } = app;

  const Questions = app.model.define('Questions', {
    id: {
      allowNull: false,
      autoIncrement: true,
      primaryKey: true,
      type: Sequelize.INTEGER
    },
    title: {
      allowNull: false,
      type: Sequelize.STRING(32)
    },
    brief: {
      allowNull: false,
      type: Sequelize.STRING(100)
    },
    order: {
      allowNull: false,
      type: Sequelize.INTEGER,
      defaultValue: 0,
    },
    createdAt: {
      allowNull: false,
      type: Sequelize.DATE,
      get() { return moment(this.getDataValue('createdAt')).format('YYYY-MM-DD HH:mm') }
    },
    updatedAt: {
      allowNull: false,
      type: Sequelize.DATE,
      get() { return moment(this.getDataValue('updatedAt')).format('YYYY-MM-DD HH:mm') }
    },
    deletedAt: {
      type: Sequelize.DATE
    }
  }, {
    charset: 'utf8mb4',
    collate: 'utf8mb4_general_ci',
    comment: '常见问题表',
  });

  return Questions;

};